#pragma once
#include <deque>
#include <map>
#include <mutex>

using namespace std;
mutex mtx_queue_p;
struct Pos
{
	int xCoord;
	int yCoord;
	char id;
};

class Player
{
private:

	char left, right, up, down;
	int identity;
	struct Pos position;
	int size;
	deque<char> *pQueue;
	deque<Pos> *gQueue;


public:

	Player()
	{
		identity = 0;
		left = 0;
		right = 0;
		up = 0;
		down = 0;
		position.xCoord = 0;
		position.yCoord = 0;
	}

	Player(char identity, char left, char right, char up, char down, int xCoord, int yCoord, int size, deque<char> &pQueue, deque<Pos> &gQueue)
	{
		position.id = identity;
		this->left = left;
		this->right = right;
		this->up = up;
		this->down = down;
		position.xCoord = xCoord;
		position.yCoord = yCoord;
		this->size = size;
		this->pQueue = &pQueue;
		this->gQueue = &gQueue;

	}

	Pos GetPos()
	{
		return position;
	}
	//int GetID()
	//{
	//	return identity;
	//}

	//bool HasKey(char c)
	//{
	//	if (c == up || c == down || c == left || c == right)
	//	{
	//		return true;
	//	}
	//	else
	//	{
	//		return false;
	//	}
	//}

	
	void MovePlayer()
	{
		//map<int, Pos> playerPos;
		mtx_queue_p.lock();
		if (!pQueue->empty())
		{
			char c = pQueue->front();
			pQueue->pop_front();

			if (c == up && position.yCoord > 0)
				position.yCoord--;
			else if (c == down && position.yCoord < size - 1)
				position.yCoord++;
			else if (c == left && position.xCoord > 0)
				position.xCoord--;
			else if (c == right && position.xCoord < size - 1)
				position.xCoord++;

			gQueue->push_back(position);
		}
		mtx_queue_p.unlock();
	}

	void operator() ()
	{
		while (true)
		{
			MovePlayer();
		}
	}

	~Player()
	{
	}
};

